package com.hmh.student.students.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hmh.student.students.entity.Student;
import com.hmh.student.students.entity.StudentCourse;
import com.hmh.student.students.mapper.StudentCourseMapper;
import com.hmh.student.students.mapper.StudentMapper;
import com.hmh.student.students.service.IStudentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmh.student.system.entity.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xyf
 * @since 2025-04-16
 */
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements IStudentService {
    @Autowired
    private StudentMapper studentMapper;

    //分页查询
    @Override
    public Page<Student> queryStudentPage(String name, String gender, Integer pageSize, Integer current) {
         QueryWrapper<Student> queryWrapper = new QueryWrapper<>();
         if (gender != null) {
             queryWrapper.like("gender", gender);
         }
         if (name != null&&!name.isEmpty()) {
             queryWrapper.like("name", name);
         }

         Page<Student> page = new Page<>(current, pageSize);

        return this.page(page, queryWrapper);
    }

    @Override
    public boolean existsById(Integer studentNo) {
      if (studentNo ==null) return false;
      return studentMapper.selectCount(new LambdaQueryWrapper<Student>().eq(Student::getStudentNo, studentNo)) > 0;
    }


}
